/*
 * Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
 *
 * Licensed under the Mulan PSL v2.
 * You can use this file according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of the License at
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
 * FOR MORE DETAILS.
 */

#pragma once

#include "highfive/H5File.hpp"

#include "DBManager/IRepository/Input/Element/IPartitionElementCacheRepository.h"
#include "DBManager/Repository/HDF5/Base/MainlyRepositoryBase.h"

#include "P2ECacheRepository.h"

SG_DBMANAGER_HDF5_NAMESPACE_OPEN

using namespace SG::DBManager;

/**
 * @brief    分区结果的HDF5实现，用于存储分区号与单元ID的映射关系
 * @author   wuxingchuang
 * @date     2025.07.24
 */
class PartitionElementCacheRepository : public IPartitionElementCacheRepository, public MainlyRepositoryBase<SG::DBManager::TwoLayersData>
{
  public:
    explicit PartitionElementCacheRepository (HDF5Database& database);

    virtual ~PartitionElementCacheRepository () = default;
    enum DATASET : std::uint8_t
    {
        MainDataset,
        IndexDataset,
        SubDataset
    };

    /**
     * @brief   : 初始化表数据
     * @author  : wxc
     */
    void InitialDatasetInfo () override;

    /**
     * @brief   : 将缓存数据转储到文件内
     */
    void DumpWriteCahce () override;

    /**
     * @brief   : 加载文件数据至缓存
     * @param   : loadIndex
     */
    std::vector<DataType>* LoadReadCache (std::size_t loadIndex) override;

    /**
     * @brief   : 对数据进行排序
     */
    void SortData () override;

    /**
     * @brief    Get the All Data object
     *
     * @return
     * @author   wxc
     * @date     2025.07.24
     */
    std::vector<SG::DBManager::TwoLayersData> GetAllData () override;

    /**
     * @brief   : 将自己的数据转存为nastran的数据结构
     */
    void OwnToNastran (std::vector<SG::DBManager::TwoLayersData>&            own,
                       std::vector<SG::DBManager::HDF5::P2E::IDENTITY>& _OUT IDENTITYData,
                       std::vector<SG::DataStructure::Common::I64>& _OUT     subData,
                       bool                                                  isSort = false);

    /**
     * @brief   : 将nastran的数据结构转换为自己的数据
     */
    void NastranToOwn (std::vector<SG::DBManager::HDF5::P2E::IDENTITY>& IDENTITYData,
                       std::vector<SG::DataStructure::Common::I64>&     subData,
                       std::vector<SG::DBManager::TwoLayersData>& _OUT  own);
};

SG_DBMANAGER_HDF5_NAMESPACE_CLOSE
